﻿<div id="Content-Body" style="min-width:1000px;">
    <div class="toggle toggle-filter" resource="Dictionarys-Table,Dictionarys-Table-Paging">
        <span class="data-fill" resource="Dictionarys-Table-Paging">共 @Total 条数据</span>

        <button value="'[E]Type':undefined" class="item active">所有字典</button>
        <div class="inline-block" command="ReadTreeAuthorizeDictionarys" id="Dictionary-Filter" menu-name="字典筛选器">

        </div>
    </div>
    <div class="tools">

        <!--<input type="button" class="button right super-search" resource="Dictionarys-Table" value="高级搜索" />-->
        <form class="filter right" resource="Dictionarys-Table,Dictionarys-Table-Paging">
            <input class="left w280 input" type="text" name="[Fuzzy]Name" placeholder="搜索名称..." /><input type="submit" class="right button" value="Q" />
        </form>

        <!--<input type="button" class="tool button refresh" resource="Dictionarys-Table" value="刷新" />-->
        <input type="button" class="tool button insert" resource="Dictionarys-Table" frame="TempDictionaryFrame" command="InsertDictionary" value="新增" />
        <input type="button" class="tool button update" resource="Dictionarys-Table" frame="TempDictionaryFrame" command="UpdateDictionary" value="修改" />
        <input type="button" class="tool button delete" resource="Dictionarys-Table" command="DeleteDictionary" value="删除" />
    </div>
    <div class="table-box">
        <table class="table" id="Dictionarys-Table" command="ReadPageDictionarys" parameters="Begin:1,End:12,DefaultOrders:'AType,DValue'">
            <thead>
                <tr>
                    <td name="selection" style="width:30px;"><input type="checkbox" /></td>
                    <td class="sort" name="Id" style="width:30px;">ID</td>
                    <td class="sort" name="Type" style="width:120px;">字典类型</td>
                    <td class="sort" name="Name" style="width:120px;">字典名称</td>
                    <td class="sort" name="Value" style="width:120px;">字典值</td>
                    <td class="sort" name="Description" style="width:120px;">字典说明</td>
                    <td class="sort" name="ExtraParams" style="width:120px;">附加参数</td>
                </tr>
            </thead>
        </table>
    </div>
    <div id="Dictionarys-Table-Paging" command="GetDictionarysTotal" resource="Dictionarys-Table"></div>
    <form id="TempDictionaryFrame" text="字典信息" class="frame temp" onsubmit="return app.frameSubmit(this)" style="width:480px;height:420px;margin-left: 0px; margin-top: 0px; top: 20%; left: 20%;">
        <div class="top">
            <div class="right">
                <span class="min" title="最小化"></span>
                <span class="max" title="最大化"></span>
                <span class="close" title="关闭"></span>
            </div>
            <span class="title">查看/修改字典信息</span>
        </div>
        <div class="content" readonly-where="data.Readonly">
            <div class="content">
                <span class="title">基本信息</span>
                <input type="hidden" name="Id" />
                <div class="item">
                    <label class="text">字典类型：</label>
                    <input verify="notNull" class="input w280" type="text" name="Type" placeholder="字典类型" />
                </div>
                <div class="item">
                    <label class="text">字典说明：</label>
                    <input verify="notNull" class="input w280" type="text" name="Description" placeholder="字典说明" />
                </div>
                <div class="item" id="_Value">
                    <label class="text">字典值：</label>
                    <input verify="notNull" class="input w280" type="text" name="Value" placeholder="字典值" />
                </div>
                <div class="item" id="_Name">
                    <label class="text">字典名称：</label>
                    <input verify="notNull" class="input w280" type="text" name="Name" placeholder="字典名称" />
                </div>
                <div class="item" id="_ExtraParams">
                    <label class="text">附加参数：</label>
                    <input class="input w280" type="text" name="ExtraParams" placeholder="附加参数" />
                </div>
                <div class="item" id="_Tips">
                    <span class="tip w280"></span>
                </div>
            </div>
        </div>
        <div class="bottom">
            <input type="submit" class="button" value="保存修改" display-where="!data.Readonly" />
            <input type="button" class="button close" value="返回" />
        </div>
    </form>

    <script>
        // <script> 标签默认在页面授权之前执行，setTimeout 使其在页面授权之后执行。
        setTimeout(function () {
            $("#TempDictionaryFrame").on("process", function (e, Data) {
            });

            $("#TempDictionaryFrame").on("apply", function (e, Data) {

                var Names = {
                    ExtraParams: "附加参数",
                    Name: "字典名称",
                    NameTemp: "",
                    Value: "字典值",
                    ValueTemp: "",
                    ValueIsReadOnly: false,
                    Tips: ""
                };

                var ExtraParamsName = null;

                switch (Data.Type) {
                }

                var ExtraParams = $(this).find("#_ExtraParams");
                var Name = $(this).find("#_Name");
                var Value = $(this).find("#_Value");
                var Tips = $(this).find("#_Tips");

                if (Names.ExtraParams) {
                    ExtraParams.css("display", "inline-block");
                    ExtraParams.find(".text").html(Names.ExtraParams + "：");
                    ExtraParams.find(".input").attr("placeholder", Names.ExtraParams);
                } else {
                    ExtraParams.css("display", "none");
                }

                Name.find(".text").html(Names.Name + "：");
                Name.find(".input").attr("placeholder", Names.Name + " " + Names.NameTemp);

                Value.find(".text").html(Names.Value + "：");
                Value.find(".input").attr("placeholder", Names.Value + " " + Names.ValueTemp);
                if (Names.ValueIsReadOnly) {
                    Value.find(".input").attr("disabled", "disabled");
                } else {
                    Value.find(".input").removeAttr("disabled");
                }

                if (Names.Tips) {
                    Tips.css("display", "inline-block");
                    Tips.find(".tip").html(Names.Tips);

                } else {
                    Tips.css("display", "none");
                }
            });
            $("#TempDictionaryFrame").on("show", function (e) {
                var Item = DictionaryFilter.find(".item.active");

                var Data = Item.prop("data") || { Id: "", Name: "", MaxValue: 0 };

                app.apply($(this), { Type: Data.Id, Description: Data.Name, MaxValue: Data.MaxValue });
            });


            $.extend(window, {
            });

            var DictionaryFilter = $("#Dictionary-Filter");

            if (DictionaryFilter.length) {
                var isFirst = true;

                app.server({ Command: DictionaryFilter.attr("command"), Id: "-", RoleId: 0 }, function (Result) {
                    $(Result).each(function () {


                        var Item = $("<button value=\"'[E]Type':'" + this.Id + "'\" class=\"item\">" + this.Name + "</button>");

                        Item.prop("data", this);

                        DictionaryFilter.append(Item);

                        if (isFirst) {
                            var table = $("#Dictionarys-Table");
                            table.attr("parameters", table.attr("parameters") + ",'[E]Type':'" + this.Id + "'");
                            Item.addClass("active");

                            isFirst = false;
                        }
                    });

                    InitContent();

                    if (!isFirst) {
                        DictionaryFilter.parent().find(".item:first").remove();
                    }
                });
            }

            function InitContent() {
                app.control($("#Dictionarys-Table"), "table");
                app.control($("#Dictionarys-Table-Paging"), "paging");
                app.control($("#Content-Body"), "content");
            }
        });
    </script>
</div>